package com.pang.security.auth;

import cn.hutool.core.util.StrUtil;
import com.pang.security.controller.SecurityController;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import springfox.documentation.spring.web.json.Json;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @version 1.0
 * 功能目的描述 ：用于   注销的处理类      ========>>>>>>>>>>>
 * @author： pang-yun
 * @date： 2021-06-23 19:55
 */
@Component
public class MyLogoutHandler extends JSONAuthentication implements LogoutHandler {
    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        String headerToken  = request.getHeader("Authorization");
        System.out.println("logout header Token = "+ headerToken);
        System.out.println("logout request getMethod = "+ request.getMethod());
        if (!StrUtil.isEmpty(headerToken)){
            headerToken.replace("Bearer","").trim();
            System.out.println("authentication=" +authentication);
            SecurityContextHolder.clearContext();
        }
    }
}
